#include "privateform.h"
#include "ui_privateform.h"
#include <QStringBuilder>

PrivateForm::PrivateForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PrivateForm)
{
    ui->setupUi(this);
}

PrivateForm::~PrivateForm()
{
    delete ui;
}

void PrivateForm::closeEvent(QCloseEvent *ev)
{
    emit signalPrivateFormClose(ui->lb_other_ID->text());
}

void PrivateForm::initForm(QString id, QString name)
{
    ui->lb_local_ID->setText(GlobalVars::g_localUser.getID());
    ui->lb_other_ID->setText(id);
    ui->lb_local_name->setText(GlobalVars::g_localUser.getName());
    ui->lb_other_name->setText(name);
}

void PrivateForm::on_pb_save_clicked()
{
    QString msg = GlobalVars::g_localUser.getName()
            % QString(" ") % QString("says: ")
            % ui->textEdit->toPlainText();

    QTextCursor tc = ui->textBrowser->textCursor();
    QTextCharFormat tcf = QTextCharFormat();
    tcf.setFontFamily("隶属");
    tcf.setFontPointSize(20);
    tc.insertText(msg,tcf);
    ui->textBrowser->append("\n");
    ui->textEdit->clear();

    emit signalSendMsgPrivate(ui->lb_other_ID->text(), msg);
}

void PrivateForm::GetMsgPrivateForm(QString msg)
{
    QTextCursor tc = ui->textBrowser->textCursor();
    QTextCharFormat tcf = QTextCharFormat();
    tcf.setFontFamily("隶属");
    tcf.setFontPointSize(20);
    tc.insertText(msg,tcf);
    ui->textBrowser->append("\n");
}
